#include <stdio.h>
#include <string.h>
#define N 9

int split(int a[], int low, int high)
{
    int part_element = a[low];
    for (;;)
    {
        while (low < high && part_element <= a[high])
        {
            high--;
        }
        if (low >= high)
            break;
        a[low++] = a[high];

        while (low < high && a[low] <= part_element)
        {
            low++;
        }
        if (low >= high)
            break;
        a[high--] = a[low];
    }
    a[high] = part_element;
    return high;
}

int main(int argc, char *argv[])
{

    int n;
    scanf("%d", &n);
    while (n--)
    {
        int nums[9];
        for (size_t i = 0; i < 9; i++)
        {
            scanf("%d", &nums[i]);
        }

        int tepNum[N] = {0};
        for (size_t i = 0; i < N; i++)
        {
            tepNum[i] = nums[i];
        }

        int part_element = nums[0];
        int low = 0;

        int i = N - 1, z = 0;
        for (; i >= 0; i--)
        {
            if (tepNum[i] < part_element)
            {
                nums[low++] = tepNum[i];
            }
        }

        nums[low++] = part_element;
        
        for (; z < N; z++)
        {
            if(tepNum[z]>part_element)
            {
                nums[low++] = tepNum[z];
            }
        }
        
        for (size_t i = 0; i < N; i++)
        {
            printf("%d ", nums[i]);
        }
        printf("\n");
    }

    return 0;
}